package org.alis.smallcc.designpatterns.behavior.memento;

import java.util.ArrayDeque;
import java.util.Deque;

import org.apache.commons.collections4.CollectionUtils;

/**
 * 双端队列实现
 * 
 * @author luochuan
 */
public class DequeCareTaker implements CareTaker{
	private Deque<Memento> deque;
	
	public DequeCareTaker() {
		deque = new ArrayDeque<>();
	}

	@Override
	public Memento pushMemento(Memento memento) {
		 deque.push(memento);
		 return memento;
	}

	@Override
	public Memento popMemento() {
		if(CollectionUtils.isEmpty(deque)) {
			throw new UnsupportedOperationException("备忘录操作已经执行完毕");
		}
		return deque.pop();
	}

}
